package com.assistant.markdown;

import lombok.Getter;
import org.springframework.util.StringUtils;

/**
 * Image
 *
 * @author yingjianhua
 */
@Getter
public class Image implements Content {

    private final String source;
    private String alternate;
    private String title;

    public Image(String source, String alternate, String title) {
        this.source = source;
        this.alternate = alternate;
        this.title = title;
    }

    public Image(String source, String alternate) {
        this.source = source;
        this.alternate = alternate;
    }

    public Image(String source) {
        this.source = source;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("![");
        if (StringUtils.hasLength(alternate)) {
            stringBuilder.append(alternate);
        }
        stringBuilder.append("](").append(source);
        if (StringUtils.hasLength(title)) {
            stringBuilder.append(" \"").append(title).append("\"");
        }
        stringBuilder.append(")");
        return stringBuilder.toString();
    }
}
